Skip to content

IconWidget

Base classes

Name Children Inherits
Label
prettyqt.widgets.label
Text or image display.

⋔ Inheritance diagram

graph TD
  2254063358["custom_widgets.IconWidget"]
  2390810357["widgets.Label"]
  1689631995["widgets.FrameMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  1485870171["QtWidgets.QLabel"]
  3822057598["QtWidgets.QFrame"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  2390810357 --> 2254063358
  1689631995 --> 2390810357
  829357528 --> 1689631995
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  2751680898 --> 1689631995
  1485870171 --> 2390810357
  3822057598 --> 1485870171
  3620195106 --> 3822057598
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: Label

Source code in prettyqt/custom_widgets/labels/iconwidget.py
class IconWidget(widgets.Label):
    def __init__(self, *names, parent: widgets.QWidget | None = None, **kwargs):
        super().__init__(parent=parent)
        self._icon: gui.QIcon | None = None
        self._size = core.Size(16, 16)
        self.set_icon(iconprovider._icon(*names, **kwargs))

    def set_icon(self, _icon: datatypes.IconType):
        """Set a new icon().

        Parameters
        ----------
        _icon: qtawesome.icon
            icon to set
        """
        self._icon = iconprovider.get_icon(_icon)
        self.setPixmap(self._icon.pixmap(self._size))

    def set_icon_size(self, size: datatypes.SizeType):
        self._size = datatypes.to_size(size)
        self.update()

    def update(self, *args, **kwargs):
        if self._icon:
            self.setPixmap(self._icon.pixmap(self._size))
        return super().update(*args, **kwargs)

set_icon(_icon: datatypes.IconType)

Set a new icon().

Parameters

_icon: qtawesome.icon icon to set

Source code in prettyqt/custom_widgets/labels/iconwidget.py
def set_icon(self, _icon: datatypes.IconType):
    """Set a new icon().

    Parameters
    ----------
    _icon: qtawesome.icon
        icon to set
    """
    self._icon = iconprovider.get_icon(_icon)
    self.setPixmap(self._icon.pixmap(self._size))

:fa-brands-github: Show source on GitHub